<?php 
	require_once 'dbHandler.php';
// ----------------------------------------------------------------
// Owner class repersent the customer of the restaurant.
// ----------------------------------------------------------------	

	class Customer
	{
		private $name = 'N/A';
		public $email = 'N/A';
		private $phone = 'N/A';
		private $address = 'N/A';
		private $password = 'N/A';
		
		
		public function __construct()
		{
			$name = 'N/A';
			$email = 'N/A';
			$phone = 'N/A';
			$address = 'N/A';
			$password = 'N/A';
		}
	
// ----------------------------------------------------------------
// Funcrtion relate to customer
// ----------------------------------------------------------------

	public function getCustomer($user, $pass)
	{
		$DTB = dbHandler::getInstance();
		$query = "SELECT * FROM customer WHERE email = '$user' AND password = '$pass'"; 
		$result = $DTB->query($query);
		$customer = new Customer();
		//return $result;
		while($row = mysql_fetch_array($result))
		{
			$customer->email = mysql_result($result,0,'email');
			$customer->name = mysql_result($result,0,'name');
			$customer->phone = mysql_result($result,0,'phone_no');
			$customer->address = mysql_result($result,0,'address');
			$customer->password = mysql_result($result,0,'password');
		}
		
		if($customer->email == $user && $customer->password == $pass)
		{
			return $customer;
		}
		else 
		{
			return $customer;
		}
	}
	
	public function getUsername()
	{
		return $this->email;	
	}
	
	public function getPassword()
	{
		return $this->password;
	}
	
	public function getAddress()
	{
		return $this->address;
	}
	
	public function getPhone()
	{
		return $this->phone;
	}
	
	public function getName()
	{
		return $this->name;
	}
	
	public function registerCustomer($usermail, $password, $phone, $name, $address)
	{
		$customer = new Customer();
		$customer->email = $usermail;
		$customer->name = $name;
		$customer->phone = $phone;
		$customer->address = $address;
		$customer->password = $password;
		
		$DTB = dbHandler::getInstance();
		$query = "SELECT email FROM customer WHERE email = '$usermail'";
		$result = $DTB->query($query);
		
		while($row = mysql_fetch_array($result))
		{
			$emailFromDB = mysql_result($result, 0, 'email');
		}
		
		if($emailFromDB == $customer->email)
		{
			return "The email selected is already in use!";
		}
		else
		{
			$query = "INSERT INTO customer(" . 
			 " email," .
			 " phone_no," .
			 " name," .
			 " address," .
			 " password)" .
			 " VALUES('" .
			 $customer->email . "', '" .
			 $customer->phone . "', '" .
			 $customer->name . "', '" .
			 $customer->address . "', '" .
			 $customer->password . 
			 "')";
			 $result = $DTB->query($query);
			return "Registration Complete";
		}
	}
	
	}
?>